import unittest
import pandas as pd
from dev.stock_information.stock_detail import get_daily_stock,get_stock_MA,get_stock_RSI,get_stock_MACD,get_aStock_zh_a_minute,get_Stock_Bollinger,get_stock_OBV
from dev.stock_information.stock_detail import get_week_stock,get_month_stock

class StockDetailTest(unittest.TestCase):

    def test_get_daily_stock(self):
        print("************   测试stock_detail.get_daily_stock   ************")
        symbol, start_date, end_date, adjust = "sz002401", "20230101", "20230120", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust=adjust)
        print(df_new)

    def test_get_aStock_zh_a_minute(self):
        print("************   测试stock_detail.get_aStock_zh_a_minute   ************")
        symbol, adjust = "sz002401", ""
        df_new = get_aStock_zh_a_minute(symbol=symbol, period="5", adjust=adjust)
        print(df_new)

    def test_get_week_stock(self):
        print("************   测试stock_detail.get_week_stock   ************")
        symbol, start_date, end_date, adjust = 'sh601728', "20220101", "20230215", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust="")
        df_new.index = df_new.date
        df_week = get_week_stock(df_new)
        print(df_week)

    def test_get_month_stock(self):
        print("************   测试stock_detail.get_month_stock   ************")
        symbol, start_date, end_date, adjust = 'sh601728', "20220101", "20230215", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust="")
        df_new.index = df_new.date
        df_month = get_month_stock(df_new)
        print(df_month)

    def test_get_stock_MA(self):
        print("************   测试stock_detail.get_stock_MA   ************")
        symbol, start_date, end_date, adjust = "sz002401", "20230101", "20230120", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust=adjust)
        MA = get_stock_MA(df_new['close'],timeperiod=5,matype=1)  # 要求df的index为Datetime类型, matype=1为EMA
        print(MA)

    def test_get_stock_MACD(self):
        print("************   测试stock_detail.get_stock_MACD   ************")
        symbol, start_date, end_date, adjust = "sz002401", "20220101", "20230120", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust=adjust)
        macd,macdsignal,macdhist = get_stock_MACD(df_new['close'],fastperiod=12,slowperiod=26,signalperiod=9)  # 要求df的index为Datetime类型
        print(f"macd={macd}\n,macdsignal={macdsignal}\n,macdhist={macdhist}\n")

    def test_get_stock_RSI(self):
        print("************   测试stock_detail.get_stock_RSI   ************")
        symbol, start_date, end_date, adjust = "sz002401", "20230101", "20230120", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust=adjust)
        RSI = get_stock_RSI(df_new['close'],timeperiod=5)  # 要求df的index为Datetime类型
        print(RSI)

    def test_get_Stock_Bollinger(self):
        print("************   测试stock_detail.get_Stock_Bollinger   ************")
        symbol, start_date, end_date, adjust = "sz002401", "20230101", "20230120", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust=adjust)
        H_line, M_line, L_line = get_Stock_Bollinger(df_new['close'],timeperiod=5,nbdevup=2,nbdevdn=2,matype=0)  # 要求df的index为Datetime类型
        print(f"H_line={H_line}\n,M_line={M_line}\n,L_line={L_line}\n")

    def test_get_stock_OBV(self):
        print("************   测试stock_detail.get_stock_OBV   ************")
        symbol, start_date, end_date, adjust = "sz002401", "20230101", "20230120", ""
        df_new = get_daily_stock(symbol=symbol, start_date=start_date, end_date=end_date, adjust=adjust)
        obv = get_stock_OBV(df_new)  # 要求df的index为Datetime类型
        print(obv)